﻿using Entity;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebProject.Controllers.Base;

namespace WebProject.Controllers
{
    public class ProCheckController : BaseController
    {
        // GET: ProCheck
        BLL.ProCheck.ProCheckBLL checkBLL;
        public ProCheckController()
        {
            checkBLL = new BLL.ProCheck.ProCheckBLL();
        }
        //创建盘点任务
        public ActionResult CreateVenTask()
        {
            return View();
        }
        //盘点任务列表
        public ActionResult TaskList()
        {
            return View();
        }
        //盘点记录（应盘）
        public ActionResult TaskRecords()
        {
            return View();
        }
        //盘点清单（实盘）
        public ActionResult CheckTaskList()
        {
            return View();
        }
        //盘点报告
        public ActionResult TaskReport()
        {
            return View();
        }
        //盘点差异
        public ActionResult checkReportResult()
        {
            return View();
        }
        public ActionResult UpdateTask()
        {
            return View();
        }

        /// <summary>
        /// 创建盘点任务
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult CreateTask(string datas, string type)
        {
            return Json(checkBLL.CreateTask(datas,type));
        }
        /// <summary>
        /// 盘点任务删除
        /// </summary>
        /// <param name="pchCode"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult DelCheckTask(string pchCode)
        {
            return Json(checkBLL.DelCheckTask(pchCode));
        }
        /// <summary>
        /// 终止盘点任务
        /// </summary>
        /// <param name="pchCode"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult StopCheckTask(string pchCode)
        {
            return Json(checkBLL.ChanageStatus(pchCode, "pct-stop"));
        }
          [HttpPost]
        public JsonResult createReport(string pchCodes)
        {
            return Json(checkBLL.createReport(pchCodes));
        }
        
        [HttpGet]
        public JsonResult GetDataList(string page, string limit, string condition, string dataType, string typesCode)
        {
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            var rsl = new ReturnResult();
            if (dataType == "erptask")
            {
                rsl = checkBLL.GetERPTask(condition);//U8盘点单列表
            }
            else if (dataType == "erptasks")
            {
                rsl = checkBLL.GetERPTasks(condition, typesCode);//U8盘点单列表 创建盘点单时获取
            }
            else if (dataType == "task")
            {
                rsl = checkBLL.GetTaskList(page, limit, ref pageCount, condition);//盘点任务表
            }
            else if (dataType == "chRds")
            {
                rsl = checkBLL.getTaskRecordsByCode(condition);//盘点清单(实盘)
            }
            else if (dataType == "chyp")
            {
                rsl = checkBLL.getYpList(page, limit, ref pageCount, condition, typesCode);//应盘列表    （检索条件 盘点编码）
            }
            else if (dataType == "report")
            {
                rsl = checkBLL.TaskReportList(page, limit, ref pageCount, condition);//盘点报告
            }
            else if (dataType == "diff")
            {
                rsl = checkBLL.getReportDiffer(condition, limit, typesCode);//盘点报告       （盘点编码 条码类型 盈亏类型）
            }
            
            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }
            JsonResult js = new JsonResult();
            return new JsonResult()
            {
                Data = new
                {
                    count = pageCount,
                    msg = msg,
                    code = "0",
                    data = datas
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

        //删除盘点报告（取消报告）
        [HttpPost]
        public JsonResult delReport(string pchCodes)
        {
            return Json(checkBLL.delReport(pchCodes));
        }

        //差异处理
        [HttpPost]
        public JsonResult DoCheckDiffer(string ids, string barType, string enType)
        {
            return Json(checkBLL.DoCheckDiffers(ids, barType, enType));
        }

        //同步结果
        [HttpPost]
        public JsonResult syncReport(string pchCodes)
        {
            return Json(checkBLL.syncReport( pchCodes));
        }


    }
}